//20175332
package 其他;
import java.io.*;
import java.*;
public class MyCP{
    public static void main(String[] args) throws IOException {
        //输入十进制文本
        String filepath = "src\\a.txt";
        String s =dataInputStream(filepath);
        //将得到的二进制数存成文本
        FileOutputStream fps = new FileOutputStream("src\\b.txt");
        fps.write(s.getBytes());
        fps.close();
    }
    public static String dataInputStream(String filepath) throws IOException {
        File file = new File(filepath);
        DataInputStream dps = new DataInputStream(new FileInputStream(file));
        StringBuilder byData = new StringBuilder();
        byte bt = 0;
        for(int i=0;i<file.length();i++) {
            //以二进制的无符号整数形式返回一个字符串表示形式
            bt = dps.readByte();
            String str = Integer.toBinaryString(bt);
            if(str.length() == 1) {
                str = "0"+str;
            }
            byData.append(str.toUpperCase());
        }
        return byData.toString();
    }
}